<?php
include "user.php";
include "dao/UserDao.php";
if(isset($_POST['loginSubmit'])){
	$dao = new UserDao();
	$user = $dao->lookupByUserName($_POST['username']);
	if($user != 0){
		session_start();
		$_SESSION['user'] = $user;
		if($_POST['username'] == 'admin'){
			header('location: ../model/admin_gen.php');
		}else{
			header('location: ../model/team.php');
		}
	}else{
		$loginFailed = "true";
		include '../view/login.php';
	}
}elseif (isset($_POST['regSubmit'])){
	$user = new user($_POST['firstname'], $_POST['lastname'], $_POST['student_id'], $_POST['username']);
	$dao = new UserDao();
	$dao->insert($user, $_POST['password']);
	session_start();
	$_SESSION['user'] = $user;
	header('location: ../model/team.php');
}else{
	include "../view/login.php";
}
?>
